package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.util.List;

import com.speaktoitcookbook.bean.Comment;
import com.speaktoitcookbook.dao.ICommentDao;
import com.speaktoitcookbook.dao.impl.CommentDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 用户评论数据操作代理类
 * 
 * @author 杨强
 * 
 */
public class CommentDaoProxy implements ICommentDao {
    private Connection conn;
    private ICommentDao dao;

    public CommentDaoProxy() {
        this.conn = Database.getInstance().getConnection();
        this.dao = new CommentDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Comment comment) {
        boolean result = false;
        if (null != comment) {
            result = dao.doCreate(comment);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doDelete(long commentID) {
        boolean result = false;
        if (commentID > 0) {
            result = dao.doDelete(commentID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doUpdate(Comment comment) {
        boolean result = false;
        if (null != comment) {
            result = dao.doUpdate(comment);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<Comment> getComment(String userID) {
        List<Comment> result = null;
        if ((null != userID) && (!userID.isEmpty())) {
            result = dao.getComment(userID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<Comment> getComment(long cookbookID) {
        List<Comment> result = null;
        if (cookbookID > 0) {
            result = dao.getComment(cookbookID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<Comment> getComment(Object... params) {
        List<Comment> result = null;
        if (null != params) {
            result = dao.getComment(params);
        }
        Database.close(conn);
        return result;
    }
}
